﻿using System;
using System.Text;
using HtmlAgilityPack;
namespace AllInfoC
{
    class WebInfo:IWebInfo
    {
        private HtmlNodeCollection _htmlNodeCollection;
        private readonly String _xPath;
        private readonly String _url;
        private HtmlNode _htmlRoot;
        
        public WebInfo(String url, String xPath)
        {
            _url = url;
            _xPath = xPath;
        }
        public void GetInfo()
        {
            var htmlWeb = new HtmlWeb();
            var htmlDocument = htmlWeb.Load(_url);
            _htmlRoot = htmlDocument.DocumentNode;
            _htmlNodeCollection = _htmlRoot.SelectNodes(_xPath);
        }
        public HtmlNodeCollection HtmlNodeCollection
        {
            get { return _htmlNodeCollection; }
        }
        public new String ToString()
        {
            var output = new StringBuilder();
            if (_htmlNodeCollection != null)
            {
                foreach (HtmlNode node in _htmlNodeCollection)
                {
                    output.Append(node.OuterHtml);
                    Console.WriteLine(node.OuterHtml);
                }
            }
            return output.ToString();
        }
    }
}
